#pragma once

#include "Utilities.h"
#include "IBitmapPicture.h"
#include <map>

///////////////////////////////////////////////
// Forward declaration
struct SubpixelInfo;

class ThresholdingIterator
{
	int mWidth, mHeight, mScale, mShortWidth, mShortHeight;
	int mWidth4;
	Array mBarbs, mThresholdData, mIntensity;
	float mThreshold, mThresholdRelative, mNoiseLevel;
	int mX, mY;

	// weak link to the buffer inside the instance of Calculator class.
	const SubpixelInfo* mSubpixelInfo; 

public:

	ThresholdingIterator(const IBitmapPicture&,
		float blurRadius, float thresholdRelative, float noiseLevel,
		float clutterSuppression);
	~ThresholdingIterator();
	
	void SetSubpixelInfo(const SubpixelInfo*);

	bool Next(int &outX, int &outY);

	float Threshold(int x, int y) const;
	float Intensity(int x, int y) const;
private:
	void AdjustToBrightness(const Array& rgb);

	//-----------------
	template<typename T>
		void Squeeze(const T* inBuffer, int offsetX, int offsetY, float* outBuffer);

	void FillData(const IBitmapPicture*, float noiseLevel, float clutterSuppression);
	float SafeSmoothValue(int x, int y, const float* p);
	void SmoothThreshold();
};

